package com.林子祺.CAT旅游系统.dao.login;

import com.林子祺.CAT旅游系统.entity.login.UserData;
import com.林子祺.CAT旅游系统.util.UserStructure;

import java.sql.*;
import java.util.ArrayList;

public class PullAccount {

    public static boolean pull(){
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/travelsys", "root", "@Blink102417");

            String sql = "select id,name from user where admin = 0";

            stmt = conn.createStatement();

            rs = stmt.executeQuery(sql);

            while (rs.next()){
                UserData.ud.add(new UserStructure(rs.getInt("id"),rs.getString("name")));
            }

            return true;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            if(rs != null) {
                try {
                    rs.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(conn != null) {
                try {
                    conn.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }
        return false;
    }

}
